﻿using System.ComponentModel;
using System.Windows;

namespace MefMvvm.Common
{
	/// <summary>
	/// Can be used to resolve whether the application is currently in design
	/// mode.
	/// </summary>
	public static class Designer
	{
		private static bool? _isInDesignMode;

		/// <summary>
		/// Gets a value indicating whether the control is in design mode (running in Blend
		/// or Visual Studio).
		/// </summary>
		public static bool IsInDesignMode
		{
			get
			{
				if (!_isInDesignMode.HasValue)
				{
#if SILVERLIGHT
					_isInDesignMode = DesignerProperties.IsInDesignTool;
#else
                    var prop = DesignerProperties.IsInDesignModeProperty;
                    _isInDesignMode
                        = (bool)DependencyPropertyDescriptor
                        .FromProperty(prop, typeof(FrameworkElement))
                        .Metadata.DefaultValue;
#endif
				}

				return _isInDesignMode.Value;
			}
		}
	}
}
